#/bin/bash

path=$3;
FileNum="$2";

DownDIR="/root/down";
LocalDIR="/root/dk";

mv_file(){
if [ "$FileNum" -eq 0 ];then
    exit 0
fi
while true; do
filepath=$path
path=${path%/*}; 
if [ "$path" = "$path" ] && [ "$FileNum" -eq 1 ];then
    mv -f ${filepath} ${LocalDIR};
    exit 0
elif [ "$path" = "$path" ];then
    cd $filepath
    get_file;
    exit 0
fi
done
}

get_file(){
IFS_BAK=$IFS;
IFS=$'\n';
for file in `ls -A1 .`
    do
     if [ -d "$file" ]; then
       eval cd \'$file\';
       get_file;
       cd ..
     else
        tfile=$(echo "$file" | tr [A-Z] [a-z]);
        if [ "${tfile##*.}"x = "mp4"x ]||[ "${tfile##*.}"x = "avi"x ]||[ "${tfile##*.}"x = "rmvb"x ]||[ "${tfile##*.}"x = "mkv"x ]||[ "${tfile##*.}"x = "rm"x ]||[ "${tfile##*.}"x = "flv"x ]||[ "${tfile##*.}"x = "mpeg"x ]||[ "${tfile##*.}"x = "vob"x ]||[ "${tfile##*.}"x = "srt"x ]||[ "${tfile##*.}"x = "ass"x ]; then
        mv -f ${file} ${LocalDIR};
        fi
     fi
    done
IFS=$IFS_BAK;
 }

mv_file